<?php
/**
 * Nuwani PHP IRC Bot Framework
 * Copyright (c) 2006-2010 The Nuwani Project
 *
 * Nuwani is a framework for IRC Bots built using PHP. Nuwani speeds up bot 
 * development by handling basic tasks as connection- and bot management, timers
 * and module managing. Features for your bot can easily be added by creating
 * your own modules, which will receive callbacks from the framework.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @copyright Copyright (c) 2006-2011 The Nuwani Project
 * @author Peter Beverloo <peter@lvp-media.com>
 * @author Dik Grapendaal <dik.grapendaal@gmail.com>
 * @see http://nuwani.googlecode.com
 */

//namespace Nuwani;

require __DIR__ . '/IrcOutput.php';

/**
 * Uno Nuwani Module
 * 
 * @copyright Copyright (c) 2011 The Nuwani Project, http://nuwani.googlecode.com/
 * @author Dik Grapendaal <dik.grapendaal@gmail.com>
 * @version $Id: UnoOutput.php 141 2011-07-23 21:47:01Z dik.grapendaal $
 * @package Modules
 */

abstract class UnoOutput
{
        /**
         * Formats a line with the given arguments before outputting it, that is
         * to say, runs it through vsprintf().
         * 
         * @param string $line The line to format.
         * @param ... $args The arguments to use.
         */
        
        public function formatPublic ($line)
        {
                $arguments = func_get_args ();
                array_shift ($arguments);
                return $this -> outputPublic (vsprintf ($line, $arguments));
        }
        
        /**
         * Formats a line with the given arguments before sending it to the
         * given player, that is to say, runs it through vsprintf().
         * 
         * @param string $player The player to send it to.
         * @param string $line The line to format.
         * @param ... $args The arguments to use.
         */
        
        public function formatPrivate ($player, $line)
        {
                $arguments = func_get_args ();
                array_shift ($arguments); array_shift ($arguments);
                return $this -> outputPrivate ($player, vsprintf ($line, $arguments));
        }
        
        /**
         * Sends a line to the public output destination.
         * 
         * @param string $line The line to format.
         */
        
        abstract public function outputPublic ($line);
        
        /**
         * Sends a line to the specified player, which only he or she will see.
         * 
         * @param string $player The player to send it to.
         * @param string $line The line to format.
         */
        
        abstract public function outputPrivate ($player, $line);
        
        /**
         * Formats the given card for display.
         * 
         * @param UnoCard $card The card to format.
         */
        
        public function formatCard (UnoCard $card)
        {
                $output = $this -> formatCardProperties ($card -> getColor (), $card -> getNumber ());
                
                if ($card -> isWildcard () && $card -> getNextColor () !== null)
                {
                        $output .= ' ';
                        $output .= $this -> formatCardProperties ($card -> getNextColor ());
                }
                
                return $output;
        }
        
        /**
         * Formats a card as with the given properties.
         * 
         * @param int $color The color.
         * @param int $number The number.
         * @return string
         */
        
        abstract public function formatCardProperties ($color, $number = UnoEngine :: CARD_NONE);
        
        
        /**
         * Saves the scores with this output method.
         * 
         * @param int $score The score of the winning player.
         * @param string $winner The name of the winning player.
         * @param array $losers Array of with names of the losing players.
         */
        
        abstract public function saveScores ($score, $winner, $losers);
        
        /**
         * Save some arbitrary statistics about this Uno engine.
         * 
         * @param int $playTime The time the round took in seconds.
         * @param int $endScore The score achieved by the winner.
         */
        
        abstract public function saveStatistics ($playTime, $endScore);
}